{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Saving vectors of label - 'happy': 100%|██████████| 1742/1742 [00:06<00:00, 272.79it/s]\n",
      "Saving vectors of label - 'bed': 100%|██████████| 1713/1713 [00:06<00:00, 285.00it/s]\n",
      "Saving vectors of label - 'cat': 100%|██████████| 1733/1733 [00:06<00:00, 256.58it/s]\n"
     ]
    }
   ],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2   #自动重新装入, 2:装入所有 %aimport 不包含的模块\n",
    "\n",
    "from preprocess import *\n",
    "import keras\n",
    "from keras.models import Sequential\n",
    "from keras.layers import Dense, Dropout, Flatten, Conv2D, MaxPooling2D\n",
    "from keras.utils import to_categorical\n",
    "\n",
    "# Second dimension of the feature is dim2\n",
    "feature_dim_2 = 11\n",
    "\n",
    "# Save data to array file first\n",
    "save_data_to_array(max_len = feature_dim_2)\n",
    "\n",
    "# Loading train set and test set\n",
    "X_train, X_test, y_train, y_test = get_train_test()\n",
    "\n",
    "# # Feature dimension\n",
    "feature_dim_1 = 20\n",
    "channel = 1\n",
    "epochs = 50\n",
    "batch_size = 100\n",
    "verbose = 1\n",
    "num_classes = 3\n",
    "\n",
    "# Reshaping to perform 2D convolution\n",
    "X_train = X_train.reshape(X_train.shape[0], feature_dim_1, feature_dim_2, channel)\n",
    "X_test = X_test.reshape(X_test.shape[0], feature_dim_1, feature_dim_2, channel)\n",
    "\n",
    "y_train_hot = to_categorical(y_train)\n",
    "y_test_hot = to_categorical(y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_model():\n",
    "    model = Sequential()\n",
    "    model.add(Conv2D(32, kernel_size=(2, 2), activation='relu', input_shape=(feature_dim_1, feature_dim_2, channel)))\n",
    "    model.add(Conv2D(48, kernel_size=(2, 2), activation='relu'))\n",
    "    model.add(Conv2D(120, kernel_size=(2, 2), activation='relu'))\n",
    "    model.add(MaxPooling2D(pool_size=(2, 2)))\n",
    "    model.add(Dropout(0.25))\n",
    "    model.add(Flatten())\n",
    "    model.add(Dense(128, activation='relu'))\n",
    "    model.add(Dropout(0.25))\n",
    "    model.add(Dense(64, activation='relu'))\n",
    "    model.add(Dropout(0.4))\n",
    "    model.add(Dense(num_classes, activation='softmax'))\n",
    "    model.compile(loss=keras.losses.categorical_crossentropy,\n",
    "                  optimizer=keras.optimizers.Adadelta(),\n",
    "                  metrics=['accuracy'])\n",
    "    return model\n",
    "\n",
    "# Predicts one sample\n",
    "def predict(filepath, model):\n",
    "    sample = wav2mfcc(filepath)\n",
    "    sample_reshaped = sample.reshape(1, feature_dim_1, feature_dim_2, channel)\n",
    "    return get_labels()[0][np.argmax(model.predict(sample_reshaped))]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Building The Model Then Training it"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Train on 3112 samples, validate on 2076 samples\n",
      "Epoch 1/50\n",
      "3112/3112 [==============================] - 4s 1ms/step - loss: 1.6354 - acc: 0.4515 - val_loss: 0.7520 - val_acc: 0.7182\n",
      "Epoch 2/50\n",
      "3112/3112 [==============================] - 0s 120us/step - loss: 0.7653 - acc: 0.6799 - val_loss: 0.5692 - val_acc: 0.7813\n",
      "Epoch 3/50\n",
      "3112/3112 [==============================] - 0s 109us/step - loss: 0.5992 - acc: 0.7654 - val_loss: 0.4021 - val_acc: 0.8531\n",
      "Epoch 4/50\n",
      "3112/3112 [==============================] - 0s 119us/step - loss: 0.4842 - acc: 0.8239 - val_loss: 0.3205 - val_acc: 0.8887\n",
      "Epoch 5/50\n",
      "3112/3112 [==============================] - 0s 106us/step - loss: 0.3765 - acc: 0.8631 - val_loss: 0.7657 - val_acc: 0.7298\n",
      "Epoch 6/50\n",
      "3112/3112 [==============================] - 0s 107us/step - loss: 0.3378 - acc: 0.8740 - val_loss: 0.2720 - val_acc: 0.9118\n",
      "Epoch 7/50\n",
      "3112/3112 [==============================] - 0s 111us/step - loss: 0.2613 - acc: 0.9174 - val_loss: 0.2487 - val_acc: 0.9128\n",
      "Epoch 8/50\n",
      "3112/3112 [==============================] - 0s 109us/step - loss: 0.2429 - acc: 0.9120 - val_loss: 0.2060 - val_acc: 0.9316\n",
      "Epoch 9/50\n",
      "3112/3112 [==============================] - 0s 119us/step - loss: 0.2167 - acc: 0.9229 - val_loss: 0.2378 - val_acc: 0.9147\n",
      "Epoch 10/50\n",
      "3112/3112 [==============================] - 0s 117us/step - loss: 0.1800 - acc: 0.9383 - val_loss: 0.2462 - val_acc: 0.9128\n",
      "Epoch 11/50\n",
      "3112/3112 [==============================] - 0s 115us/step - loss: 0.1803 - acc: 0.9422 - val_loss: 0.1759 - val_acc: 0.9393\n",
      "Epoch 12/50\n",
      "3112/3112 [==============================] - 0s 111us/step - loss: 0.1442 - acc: 0.9524 - val_loss: 0.2441 - val_acc: 0.9152\n",
      "Epoch 13/50\n",
      "3112/3112 [==============================] - 0s 115us/step - loss: 0.1198 - acc: 0.9589 - val_loss: 0.1894 - val_acc: 0.9355\n",
      "Epoch 14/50\n",
      "3112/3112 [==============================] - 0s 123us/step - loss: 0.0918 - acc: 0.9695 - val_loss: 0.1455 - val_acc: 0.9547\n",
      "Epoch 15/50\n",
      "3112/3112 [==============================] - 0s 116us/step - loss: 0.0737 - acc: 0.9781 - val_loss: 0.1695 - val_acc: 0.9513\n",
      "Epoch 16/50\n",
      "3112/3112 [==============================] - 0s 113us/step - loss: 0.0798 - acc: 0.9704 - val_loss: 0.1757 - val_acc: 0.9504\n",
      "Epoch 17/50\n",
      "3112/3112 [==============================] - 0s 115us/step - loss: 0.0690 - acc: 0.9788 - val_loss: 0.1470 - val_acc: 0.9533\n",
      "Epoch 18/50\n",
      "3112/3112 [==============================] - 0s 115us/step - loss: 0.0495 - acc: 0.9833 - val_loss: 0.1413 - val_acc: 0.9605\n",
      "Epoch 19/50\n",
      "3112/3112 [==============================] - 0s 118us/step - loss: 0.0458 - acc: 0.9836 - val_loss: 0.1678 - val_acc: 0.9581\n",
      "Epoch 20/50\n",
      "3112/3112 [==============================] - 0s 121us/step - loss: 0.0591 - acc: 0.9804 - val_loss: 0.3211 - val_acc: 0.9075\n",
      "Epoch 21/50\n",
      "3112/3112 [==============================] - 0s 108us/step - loss: 0.0603 - acc: 0.9798 - val_loss: 0.1460 - val_acc: 0.9634\n",
      "Epoch 22/50\n",
      "3112/3112 [==============================] - 0s 115us/step - loss: 0.0308 - acc: 0.9907 - val_loss: 0.1653 - val_acc: 0.9562\n",
      "Epoch 23/50\n",
      "3112/3112 [==============================] - 0s 114us/step - loss: 0.0373 - acc: 0.9894 - val_loss: 0.1650 - val_acc: 0.9552\n",
      "Epoch 24/50\n",
      "3112/3112 [==============================] - 0s 115us/step - loss: 0.0259 - acc: 0.9916 - val_loss: 0.1806 - val_acc: 0.9586\n",
      "Epoch 25/50\n",
      "3112/3112 [==============================] - 0s 115us/step - loss: 0.0244 - acc: 0.9945 - val_loss: 0.1795 - val_acc: 0.9509\n",
      "Epoch 26/50\n",
      "3112/3112 [==============================] - 0s 117us/step - loss: 0.0595 - acc: 0.9801 - val_loss: 0.1883 - val_acc: 0.9533\n",
      "Epoch 27/50\n",
      "3112/3112 [==============================] - 0s 115us/step - loss: 0.0193 - acc: 0.9945 - val_loss: 0.1808 - val_acc: 0.9571\n",
      "Epoch 28/50\n",
      "3112/3112 [==============================] - 0s 115us/step - loss: 0.0170 - acc: 0.9949 - val_loss: 0.1857 - val_acc: 0.9600\n",
      "Epoch 29/50\n",
      "3112/3112 [==============================] - 0s 116us/step - loss: 0.0211 - acc: 0.9949 - val_loss: 0.1828 - val_acc: 0.9547\n",
      "Epoch 30/50\n",
      "3112/3112 [==============================] - 0s 116us/step - loss: 0.0253 - acc: 0.9926 - val_loss: 0.1810 - val_acc: 0.9552\n",
      "Epoch 31/50\n",
      "3112/3112 [==============================] - 0s 115us/step - loss: 0.0195 - acc: 0.9949 - val_loss: 0.2226 - val_acc: 0.9547\n",
      "Epoch 32/50\n",
      "3112/3112 [==============================] - 0s 118us/step - loss: 0.0206 - acc: 0.9958 - val_loss: 0.1906 - val_acc: 0.9552\n",
      "Epoch 33/50\n",
      "3112/3112 [==============================] - 0s 117us/step - loss: 0.0121 - acc: 0.9961 - val_loss: 0.2020 - val_acc: 0.9605\n",
      "Epoch 34/50\n",
      "3112/3112 [==============================] - 0s 118us/step - loss: 0.0167 - acc: 0.9942 - val_loss: 0.3753 - val_acc: 0.9263\n",
      "Epoch 35/50\n",
      "3112/3112 [==============================] - 0s 118us/step - loss: 0.0123 - acc: 0.9961 - val_loss: 0.1868 - val_acc: 0.9644\n",
      "Epoch 36/50\n",
      "3112/3112 [==============================] - 0s 120us/step - loss: 0.0091 - acc: 0.9961 - val_loss: 0.2575 - val_acc: 0.9605\n",
      "Epoch 37/50\n",
      "3112/3112 [==============================] - 0s 119us/step - loss: 0.0203 - acc: 0.9926 - val_loss: 0.2098 - val_acc: 0.9576\n",
      "Epoch 38/50\n",
      "3112/3112 [==============================] - 0s 122us/step - loss: 0.0124 - acc: 0.9955 - val_loss: 0.1945 - val_acc: 0.9648\n",
      "Epoch 39/50\n",
      "3112/3112 [==============================] - 0s 117us/step - loss: 0.0201 - acc: 0.9939 - val_loss: 0.2002 - val_acc: 0.9586\n",
      "Epoch 40/50\n",
      "3112/3112 [==============================] - 0s 120us/step - loss: 0.0131 - acc: 0.9958 - val_loss: 0.1858 - val_acc: 0.9600\n",
      "Epoch 41/50\n",
      "3112/3112 [==============================] - 0s 115us/step - loss: 0.0141 - acc: 0.9958 - val_loss: 0.2048 - val_acc: 0.9634\n",
      "Epoch 42/50\n",
      "3112/3112 [==============================] - 0s 115us/step - loss: 0.0095 - acc: 0.9974 - val_loss: 0.1767 - val_acc: 0.9644\n",
      "Epoch 43/50\n",
      "3112/3112 [==============================] - 0s 116us/step - loss: 0.0076 - acc: 0.9978 - val_loss: 0.1875 - val_acc: 0.9639\n",
      "Epoch 44/50\n",
      "3112/3112 [==============================] - 0s 117us/step - loss: 0.0039 - acc: 0.9987 - val_loss: 0.2671 - val_acc: 0.9557\n",
      "Epoch 45/50\n",
      "3112/3112 [==============================] - 0s 109us/step - loss: 0.0216 - acc: 0.9920 - val_loss: 0.1677 - val_acc: 0.9672\n",
      "Epoch 46/50\n",
      "3112/3112 [==============================] - 0s 109us/step - loss: 0.0153 - acc: 0.9961 - val_loss: 0.2144 - val_acc: 0.9634\n",
      "Epoch 47/50\n",
      "3112/3112 [==============================] - 0s 115us/step - loss: 0.0109 - acc: 0.9965 - val_loss: 0.2116 - val_acc: 0.9629\n",
      "Epoch 48/50\n",
      "3112/3112 [==============================] - 0s 115us/step - loss: 0.0094 - acc: 0.9968 - val_loss: 0.2332 - val_acc: 0.9658\n",
      "Epoch 49/50\n",
      "3112/3112 [==============================] - 0s 117us/step - loss: 0.0053 - acc: 0.9987 - val_loss: 0.2076 - val_acc: 0.9639\n",
      "Epoch 50/50\n",
      "3112/3112 [==============================] - 0s 116us/step - loss: 0.0124 - acc: 0.9978 - val_loss: 0.2357 - val_acc: 0.9629\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<keras.callbacks.History at 0x7f1118134da0>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import os\n",
    "os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"0\"\n",
    "\n",
    "model = get_model()\n",
    "model.fit(X_train, y_train_hot, batch_size=batch_size, epochs=epochs, verbose=verbose, validation_data=(X_test, y_test_hot))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<svg height=\"848pt\" viewBox=\"0.00 0.00 215.00 848.00\" width=\"215pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       "<g class=\"graph\" id=\"graph0\" transform=\"scale(1 1) rotate(0) translate(4 844)\">\n",
       "<title>G</title>\n",
       "<polygon fill=\"white\" points=\"-4,4 -4,-844 211,-844 211,4 -4,4\" stroke=\"none\"/>\n",
       "<!-- 139711395090048 -->\n",
       "<g class=\"node\" id=\"node1\"><title>139711395090048</title>\n",
       "<polygon fill=\"none\" points=\"17.5,-803.5 17.5,-839.5 189.5,-839.5 189.5,-803.5 17.5,-803.5\" stroke=\"black\"/>\n",
       "<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"103.5\" y=\"-817.8\">conv2d_1_input: InputLayer</text>\n",
       "</g>\n",
       "<!-- 139711395089992 -->\n",
       "<g class=\"node\" id=\"node2\"><title>139711395089992</title>\n",
       "<polygon fill=\"none\" points=\"42,-730.5 42,-766.5 165,-766.5 165,-730.5 42,-730.5\" stroke=\"black\"/>\n",
       "<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"103.5\" y=\"-744.8\">conv2d_1: Conv2D</text>\n",
       "</g>\n",
       "<!-- 139711395090048&#45;&gt;139711395089992 -->\n",
       "<g class=\"edge\" id=\"edge1\"><title>139711395090048-&gt;139711395089992</title>\n",
       "<path d=\"M103.5,-803.313C103.5,-795.289 103.5,-785.547 103.5,-776.569\" fill=\"none\" stroke=\"black\"/>\n",
       "<polygon fill=\"black\" points=\"107,-776.529 103.5,-766.529 100,-776.529 107,-776.529\" stroke=\"black\"/>\n",
       "</g>\n",
       "<!-- 139713441527008 -->\n",
       "<g class=\"node\" id=\"node3\"><title>139713441527008</title>\n",
       "<polygon fill=\"none\" points=\"42,-657.5 42,-693.5 165,-693.5 165,-657.5 42,-657.5\" stroke=\"black\"/>\n",
       "<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"103.5\" y=\"-671.8\">conv2d_2: Conv2D</text>\n",
       "</g>\n",
       "<!-- 139711395089992&#45;&gt;139713441527008 -->\n",
       "<g class=\"edge\" id=\"edge2\"><title>139711395089992-&gt;139713441527008</title>\n",
       "<path d=\"M103.5,-730.313C103.5,-722.289 103.5,-712.547 103.5,-703.569\" fill=\"none\" stroke=\"black\"/>\n",
       "<polygon fill=\"black\" points=\"107,-703.529 103.5,-693.529 100,-703.529 107,-703.529\" stroke=\"black\"/>\n",
       "</g>\n",
       "<!-- 139711395010432 -->\n",
       "<g class=\"node\" id=\"node4\"><title>139711395010432</title>\n",
       "<polygon fill=\"none\" points=\"42,-584.5 42,-620.5 165,-620.5 165,-584.5 42,-584.5\" stroke=\"black\"/>\n",
       "<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"103.5\" y=\"-598.8\">conv2d_3: Conv2D</text>\n",
       "</g>\n",
       "<!-- 139713441527008&#45;&gt;139711395010432 -->\n",
       "<g class=\"edge\" id=\"edge3\"><title>139713441527008-&gt;139711395010432</title>\n",
       "<path d=\"M103.5,-657.313C103.5,-649.289 103.5,-639.547 103.5,-630.569\" fill=\"none\" stroke=\"black\"/>\n",
       "<polygon fill=\"black\" points=\"107,-630.529 103.5,-620.529 100,-630.529 107,-630.529\" stroke=\"black\"/>\n",
       "</g>\n",
       "<!-- 139711394958528 -->\n",
       "<g class=\"node\" id=\"node5\"><title>139711394958528</title>\n",
       "<polygon fill=\"none\" points=\"0,-511.5 0,-547.5 207,-547.5 207,-511.5 0,-511.5\" stroke=\"black\"/>\n",
       "<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"103.5\" y=\"-525.8\">max_pooling2d_1: MaxPooling2D</text>\n",
       "</g>\n",
       "<!-- 139711395010432&#45;&gt;139711394958528 -->\n",
       "<g class=\"edge\" id=\"edge4\"><title>139711395010432-&gt;139711394958528</title>\n",
       "<path d=\"M103.5,-584.313C103.5,-576.289 103.5,-566.547 103.5,-557.569\" fill=\"none\" stroke=\"black\"/>\n",
       "<polygon fill=\"black\" points=\"107,-557.529 103.5,-547.529 100,-557.529 107,-557.529\" stroke=\"black\"/>\n",
       "</g>\n",
       "<!-- 139711394806920 -->\n",
       "<g class=\"node\" id=\"node6\"><title>139711394806920</title>\n",
       "<polygon fill=\"none\" points=\"41,-438.5 41,-474.5 166,-474.5 166,-438.5 41,-438.5\" stroke=\"black\"/>\n",
       "<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"103.5\" y=\"-452.8\">dropout_1: Dropout</text>\n",
       "</g>\n",
       "<!-- 139711394958528&#45;&gt;139711394806920 -->\n",
       "<g class=\"edge\" id=\"edge5\"><title>139711394958528-&gt;139711394806920</title>\n",
       "<path d=\"M103.5,-511.313C103.5,-503.289 103.5,-493.547 103.5,-484.569\" fill=\"none\" stroke=\"black\"/>\n",
       "<polygon fill=\"black\" points=\"107,-484.529 103.5,-474.529 100,-484.529 107,-484.529\" stroke=\"black\"/>\n",
       "</g>\n",
       "<!-- 139711394807648 -->\n",
       "<g class=\"node\" id=\"node7\"><title>139711394807648</title>\n",
       "<polygon fill=\"none\" points=\"48.5,-365.5 48.5,-401.5 158.5,-401.5 158.5,-365.5 48.5,-365.5\" stroke=\"black\"/>\n",
       "<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"103.5\" y=\"-379.8\">flatten_1: Flatten</text>\n",
       "</g>\n",
       "<!-- 139711394806920&#45;&gt;139711394807648 -->\n",
       "<g class=\"edge\" id=\"edge6\"><title>139711394806920-&gt;139711394807648</title>\n",
       "<path d=\"M103.5,-438.313C103.5,-430.289 103.5,-420.547 103.5,-411.569\" fill=\"none\" stroke=\"black\"/>\n",
       "<polygon fill=\"black\" points=\"107,-411.529 103.5,-401.529 100,-411.529 107,-411.529\" stroke=\"black\"/>\n",
       "</g>\n",
       "<!-- 139711394373248 -->\n",
       "<g class=\"node\" id=\"node8\"><title>139711394373248</title>\n",
       "<polygon fill=\"none\" points=\"52.5,-292.5 52.5,-328.5 154.5,-328.5 154.5,-292.5 52.5,-292.5\" stroke=\"black\"/>\n",
       "<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"103.5\" y=\"-306.8\">dense_1: Dense</text>\n",
       "</g>\n",
       "<!-- 139711394807648&#45;&gt;139711394373248 -->\n",
       "<g class=\"edge\" id=\"edge7\"><title>139711394807648-&gt;139711394373248</title>\n",
       "<path d=\"M103.5,-365.313C103.5,-357.289 103.5,-347.547 103.5,-338.569\" fill=\"none\" stroke=\"black\"/>\n",
       "<polygon fill=\"black\" points=\"107,-338.529 103.5,-328.529 100,-338.529 107,-338.529\" stroke=\"black\"/>\n",
       "</g>\n",
       "<!-- 139711394222712 -->\n",
       "<g class=\"node\" id=\"node9\"><title>139711394222712</title>\n",
       "<polygon fill=\"none\" points=\"41,-219.5 41,-255.5 166,-255.5 166,-219.5 41,-219.5\" stroke=\"black\"/>\n",
       "<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"103.5\" y=\"-233.8\">dropout_2: Dropout</text>\n",
       "</g>\n",
       "<!-- 139711394373248&#45;&gt;139711394222712 -->\n",
       "<g class=\"edge\" id=\"edge8\"><title>139711394373248-&gt;139711394222712</title>\n",
       "<path d=\"M103.5,-292.313C103.5,-284.289 103.5,-274.547 103.5,-265.569\" fill=\"none\" stroke=\"black\"/>\n",
       "<polygon fill=\"black\" points=\"107,-265.529 103.5,-255.529 100,-265.529 107,-265.529\" stroke=\"black\"/>\n",
       "</g>\n",
       "<!-- 139711394223832 -->\n",
       "<g class=\"node\" id=\"node10\"><title>139711394223832</title>\n",
       "<polygon fill=\"none\" points=\"52.5,-146.5 52.5,-182.5 154.5,-182.5 154.5,-146.5 52.5,-146.5\" stroke=\"black\"/>\n",
       "<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"103.5\" y=\"-160.8\">dense_2: Dense</text>\n",
       "</g>\n",
       "<!-- 139711394222712&#45;&gt;139711394223832 -->\n",
       "<g class=\"edge\" id=\"edge9\"><title>139711394222712-&gt;139711394223832</title>\n",
       "<path d=\"M103.5,-219.313C103.5,-211.289 103.5,-201.547 103.5,-192.569\" fill=\"none\" stroke=\"black\"/>\n",
       "<polygon fill=\"black\" points=\"107,-192.529 103.5,-182.529 100,-192.529 107,-192.529\" stroke=\"black\"/>\n",
       "</g>\n",
       "<!-- 139711198383800 -->\n",
       "<g class=\"node\" id=\"node11\"><title>139711198383800</title>\n",
       "<polygon fill=\"none\" points=\"41,-73.5 41,-109.5 166,-109.5 166,-73.5 41,-73.5\" stroke=\"black\"/>\n",
       "<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"103.5\" y=\"-87.8\">dropout_3: Dropout</text>\n",
       "</g>\n",
       "<!-- 139711394223832&#45;&gt;139711198383800 -->\n",
       "<g class=\"edge\" id=\"edge10\"><title>139711394223832-&gt;139711198383800</title>\n",
       "<path d=\"M103.5,-146.313C103.5,-138.289 103.5,-128.547 103.5,-119.569\" fill=\"none\" stroke=\"black\"/>\n",
       "<polygon fill=\"black\" points=\"107,-119.529 103.5,-109.529 100,-119.529 107,-119.529\" stroke=\"black\"/>\n",
       "</g>\n",
       "<!-- 139711198383632 -->\n",
       "<g class=\"node\" id=\"node12\"><title>139711198383632</title>\n",
       "<polygon fill=\"none\" points=\"52.5,-0.5 52.5,-36.5 154.5,-36.5 154.5,-0.5 52.5,-0.5\" stroke=\"black\"/>\n",
       "<text font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"103.5\" y=\"-14.8\">dense_3: Dense</text>\n",
       "</g>\n",
       "<!-- 139711198383800&#45;&gt;139711198383632 -->\n",
       "<g class=\"edge\" id=\"edge11\"><title>139711198383800-&gt;139711198383632</title>\n",
       "<path d=\"M103.5,-73.3129C103.5,-65.2895 103.5,-55.5475 103.5,-46.5691\" fill=\"none\" stroke=\"black\"/>\n",
       "<polygon fill=\"black\" points=\"107,-46.5288 103.5,-36.5288 100,-46.5289 107,-46.5288\" stroke=\"black\"/>\n",
       "</g>\n",
       "</g>\n",
       "</svg>"
      ],
      "text/plain": [
       "<IPython.core.display.SVG object>"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from keras.utils import plot_model\n",
    "from IPython.display import SVG\n",
    "from keras.utils.vis_utils import model_to_dot\n",
    "\n",
    "#plot_model(model, show_shapes=True, to_file='model.png')  # 保存图片到本地\n",
    "SVG(model_to_dot(model).create(prog='dot', format='svg'))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Prediction"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "happy\n"
     ]
    }
   ],
   "source": [
    "print(predict('./data/happy/2b3f509b_nohash_1.wav', model=model))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
